<!-- 分销中心  -->
<template>
	<s-layout class="index-wrap" title="收益" onShareAppMessage>
		<view class="main">
			<view class="topPageSet ss-flex">
				<view :class="['topPageSet-item',{active:state.pageType == item.type}]" v-for="item in list"
					:key="item.type" @click="setPage(item)">
					<view class="tips" v-if="state.pageType == item.type">已选</view>
					<image class="topPageSet-img" :src="sheep.$url.cdn(item.img)" mode="aspectFill" />
					<view class="topPageSet-label">{{item.name}}</view>
				</view>
			</view>
			<!-- 我的收益 -->
			<template v-if="state.pageType == 'my'">
				<view class="ss-flex ss-p-l-20 ss-m-t-20">
					<button v-for="(item,index) in btnList.my" :key="item.value" @tap="incomeChange(item)"
						:class="['ss-reset-button tabBtn',{'tabBtn-act':state.tabActive === item.value}]">
						{{item.name}}
					</button>
				</view>
				<!-- 钱包卡片 -->
				<view class="header-box ss-m-x-22 ss-m-t-30">
					<view class="ss-flex font-w ss-m-b-20">
						<view style="font-size:30rpx">{{calcTitle}}（元）</view>
						<view @tap="state.showMoney = !state.showMoney" class="ss-eye-icon font-3"
							:class="state.showMoney ? 'cicon-eye' : 'cicon-eye-off'"></view>
					</view>
					<view class="font-w" style="font-size:40rpx">{{state.showMoney?state.total_income:'******'}}
					</view>

					<view class="ss-flex ss-m-t-24 text-center" style="color:#647BB0;line-height: 2em;">
						<view class="">
							<view>待结算</view>
							<view>{{state.showMoney?state.pending_amount:'****'}}</view>
						</view>
						<view class="ss-m-x-80">
							<view>已结算</view>
							<view>{{state.showMoney?state.settled_amount:'****'}}</view>
						</view>
						<view class="">
							<view>已退款</view>
							<view>{{state.showMoney?state.refunded_amount:'****'}}</view>
						</view>
					</view>
				</view>
				<withdraw-card :data="state.can_withdraw" />
				<su-sticky class="ss-m-t-20">

					<view class="listScreen ss-flex ss-row-around ss-p-x-20"
						:style="{top: sheep.$platform.device.statusBarHeight + 94 + 'px'}">

						<uni-datetime-picker v-model="state.timeDate" type="daterange" @tap="openTypeList(0)"
							@change="onChangeTime" :end="state.today">
							<view class="listScreen-item  ss-flex ss-row-center ss-p-l-20 "
								style="min-width:250!important;"
								:class="{ active_color: state.type==0,unactive_color:state.type!=0}">
								<view class="ss-line-1">{{ dateFilterText }}</view>
								<uni-icons class="ss-m-l-10" type="bottom" size="10"></uni-icons>
							</view>
						</uni-datetime-picker>

						<view class="listScreen-item ss-flex ss-row-center" @tap="openTypeList(1)"
							:class="{ active_color: state.type==1,unactive_color:state.type!=1}">
							<view>{{state.typeText}}<uni-icons class="ss-m-l-10" type="bottom" size="10"></uni-icons>
							</view>
						</view>
						<view class="listScreen-item ss-flex ss-row-center" @tap="openTypeList(2)"
							:class="{ active_color: state.type==2,unactive_color:state.type!=2}">
							<view>{{state.statusText}}<uni-icons class="ss-m-l-10" type="bottom" size="10"></uni-icons>
							</view>
						</view>
					</view>
				</su-sticky>
				<view class="bg-white ss-m-t-20 ss-p-t-20">
					<view class="ss-flex ss-p-l-38">
						<image style="width:33rpx;height:30rpx"
							:src="sheep.$url.cdn('/storage/myicon/202503201009151566.png')" />
						<view class="font-w ss-m-l-12" style="color:#303335;font-size:30rpx">收益明细</view>
					</view>
					<scroll-view :style="{ height: pageHeight + 'rpx' }" scroll-y="true" :scroll-with-animation="false"
						:enable-back-to-top="true">
						<view v-for="item in state.list" :key="item.id" class="ss-p-38 font-1"
							style="border-bottom:2rpx solid #EDEDED">
							<view class="ss-flex justify-between">
								<view>{{item.type_text}}</view>
								<view style="color:#DE4330">{{item.amount}}</view>
							</view>
							<view class="ss-flex justify-between ss-m-t-22">
								<view style="color:#9C9C9C">{{item.update_time}}</view>
								<view :style="{color:
									item.status=='settled'?'#2A6DDF':
									item.status=='pending'?'#0CBCBA':'#D83724'
								}">{{item.status_text}}</view>
							</view>
						</view>
						<s-empty v-if="state.list.length == 0" :icon="sheep.$url.cdn('/mengchong/data-empty.png','ygb')"
							text="暂无数据"></s-empty>

						<uni-load-more v-if="true" :status="state.loadStatus" :content-text="{
					      contentdown: '上拉加载更多',
					    }" @tap="loadmore" />
					</scroll-view>
				</view>

				<fui-actionsheet :show="state.showType" :itemList="showList" @click="typeClick"
					@cancel="state.showType=false"></fui-actionsheet>
			</template>
			<!-- 我是商家 -->
			<template v-else>
				<!-- 收益类型 tab -->
				<view class="ss-flex ss-p-l-20 ss-m-t-20">
					<scroll-view :scroll-x="true" style="width:730rpx;height:95rpx"  scroll-with-animation>
						<view class="ss-flex">
							<button v-for="(item,index) in btnList.shop" :key="item.value" @tap="changeIndex(item.value)"
								:class="['ss-reset-button tabBtn',{'tabBtn-act':state.index === item.value}]">
								{{item.name}}
							</button>
						</view>
					</scroll-view>
				</view>
				<!-- 收益卡片 -->
				<view class="money ss-p-y-25 ss-p-x-30">
					<view class="money-top ss-flex justify-between align-center">
						<view class="ss-flex align-center">
							<view class="total-text">总收入(元)</view>
							<view class="guarantee ss-m-l-30 ss-flex align-center justify-center">
								<image class="guarantee-icon"
									src="https://xyh-static-app.oss-cn-hangzhou.aliyuncs.com/storage/myicon/20250409/f31e848b2764e18d7ef9daa6a65bf3b3.png">
								</image>
								<view>账户安全保障中</view>
							</view>
						</view>
						<view class="withdraw" @click="jump">提现到余额</view>
					</view>
					<view class="ss-flex justify-between">
						<view class="total-money ss-m-t-15">{{state.data.total_money}}</view>
						<view v-if="state.index==3" @tap="sheep.$router.go('/pages/merchant/surprise/scanCode')" class="scan-btn ss-flex">
							<uni-icons class="ss-m-r-10" color="#272636" type="scan" size="14"></uni-icons>
							扫码核销
						</view>
					</view>
					<view class="w-100 ss-flex justify-between align-center ss-m-t-30 ss-m-b-30">
						<view class="money-item">待结算<text class="ss-m-l-5">{{state.data.ing_money}}</text></view>
						<view class="money-item">可提现<text class="ss-m-l-5">{{state.data.money}}</text></view>
					</view>
					<view class="chao-mer-filter w-100  ss-m-t-16 ss-flex-row ss-row-left" v-if="state.index==1">
						<view class="chao-mer-filter-s ss-flex-row ss-row-left" @click="merchantClick(1)" v-if="state.smerchantFilterList.length>1">
							<view class="chao-mer-filter-s-txt ss-flex-row ss-col-center">我的S店铺</view>
							<view class="chao-mer-filter-s-s ss-flex-row ss-col-center" @click="state.sFilterShow=true">
								<view class="chao-mer-all">{{state.stitle||'全部'}}</view>
								<image :src="sheep.$url.cdn('/static/store/arrow_down.png')"
									style="width:29rpx;height: 21rpx;margin-left: 6rpx;"></image>
							</view>
						</view>
						
						<view class="chao-mer-filter-s ss-flex-row ss-row-left" @click="merchantClick(2)" v-if="state.hmerchantFilterList.length>1">
							<view class="chao-mer-filter-s-txt ss-flex-row ss-col-center">我的H店铺</view>
							<view class="chao-mer-filter-s-s ss-flex-row ss-col-center" @click="state.hFilterShow=true">
								<view class="chao-mer-all">{{state.htitle||'全部'}}</view>
								<image :src="sheep.$url.cdn('/static/store/arrow_down.png')"
									style="width:29rpx;height: 21rpx;margin-left: 6rpx;"></image>
							</view>
						</view>

					</view>
					<!-- <view class="w-100 ss-flex justify-between align-center ss-m-t-30 ss-m-b-30" v-if="state.index === 0 || state.index === 1">
						<view class="money-item">已退款<text class="ss-m-l-5">{{state.data.refund_money}}</text></view>
					</view> -->
				</view>
				<!-- 本周，本月，本年，自定义查询 tab -->
				<view 
					class="tabs ss-p-x-30 ss-flex justify-between align-baseline sub-title-sticky" 
					:style="{top: sheep.$platform.device.statusBarHeight + 44 + 'px'}">
					<view class="ss-flex">
						<view
							class="tabs-item" 
							:class="[state.tab_index === index ? 'tab-active' : '']"
							v-for="(item,index) in tabsList" 
							:key="index" 
							@click="changeTab(index)">{{item.name}}</view>
					</view>
					<view @tap="selecetType" class="ss-flex" v-if="state.index==3">
						{{orderType.name?orderType.name:'全部收益'}}
						<uni-icons type="down" size="20"></uni-icons>
					</view>
						
					
				</view>
				
				<!-- 收益列表-本周，本月，自定义查询 -->
				<view class="ss-safe-bottom"
					v-if="state.tab_index === 0 || state.tab_index === 1||state.tab_index === 3">
					<view v-if="state.payList">
						<view class="list ss-p-20" v-for="(item,index) in state.payList" :key="index">
							<view class="w-100 ss-flex justify-between align-center title-sticky"
								:style="{top: sheep.$platform.device.statusBarHeight + 44 + 30 + 'px'}">
								<!-- state.index 0:商城商户 1:超引擎计划 2:鲸囍供应链 -->
								<template v-if="state.index == 1 || state.index == 2">
									<picker :disabled="state.tab_index !== 1" mode="date" fields="month"
										:start="state.startDate" :end="state.endDate" @change="bindDateChange">
										<view class="ss-flex align-center">
											<view class="time ss-m-r-5">{{item.title}}</view>
											<uni-icons type="down" size="20" color="#575757"
												v-if="state.tab_index === 1"></uni-icons>
										</view>
									</picker>
								</template>
								<template v-if="state.index == 0||state.index == 3">
									<view class="ss-flex align-center">
										<view class="time ss-m-r-5">{{item.title}}</view>
									</view>
								</template>

								<view class="income">收入 ￥{{item.amount}}</view>
							</view>
							<scroll-view class="list-scroll" scroll-y="true">
								
								<view class="item" v-for="(v,p) in item.child" :key="p">
									<view class="item-left ss-flex">
										<image v-if="state.index == 3&&orderType.value=='group'" class="item-left-icon"
											src="https://jxzc-ygb.oss-cn-hangzhou.aliyuncs.com/Community/Order_icon/tuangou.png">
										</image> 
										<image v-else-if="state.index == 3&&orderType.value=='takeout'" class="item-left-icon"
											src="https://jxzc-ygb.oss-cn-hangzhou.aliyuncs.com/Community/Order_icon/waimai.png">
										</image> 
										<image v-else class="item-left-icon"
											src="https://xyh-static-app.oss-cn-hangzhou.aliyuncs.com/storage/myicon/20250409/ef808f6454df9140946d82de9bbdf1bf.png">
										</image>
										<view class="ss-flex-1 item-box-t">
											<view class="item-name ss-line-1">{{v.title}}</view>
											<template v-if="v.aftersale_status==2&&state.index==2">
												<view class="apply-amount-1-t">已退款</view>
											</template>
											<view class="w-100 ss-flex justify-between align-center ss-m-t-8">
												<view class="item-time  ss-m-r-30">{{v.date}} {{v.time}}</view>
												<view class="item-money ss-flex-1 ss-line-1 text-right">+￥{{v.fee}}
												</view>
											</view>
										</view>
									</view>
								</view>
							</scroll-view>
						</view>
					</view>
					<s-empty v-if="state.payList?.length == 0 || state.payList == null" paddingTop="100"
						icon="https://xyh-static-app.oss-cn-hangzhou.aliyuncs.com/mengchong/soldout-empty.png"
						text="暂无数据">
					</s-empty>
				</view>
				<!-- 收益列表-本年 -->
				<view class="year ss-p-20" v-if="state.tab_index === 2">
					<template v-if="state.index == 1 ||state.index == 2 ">
						<picker mode="date" fields="year" :start="state.startDate" :end="state.endDate"
							@change="bindYear">
							<view class="ss-flex align-center">
								<view class="year-title ss-m-r-5">{{state.year}}</view>
								<uni-icons type="down" size="20" color="#575757"></uni-icons>
							</view>
						</picker>
					</template>
					<template v-else>
						<view class="ss-flex align-center">
							<view class="year-title ss-m-r-5">{{state.year}}</view>
						</view>
					</template>

					<view class="year-total">共获得{{state.num}}单，合计</view>
					<tenplate v-if="state.index == 1 ||state.index == 2">
						<view class="year-money">￥{{state.fee}}</view>
					</tenplate>
					<template v-else>
						<view class="year-money">￥{{state.data.total_money}}</view>
					</template>

				</view>
			</template>
			<tui-calendar ref="calendar" isFixed :type="2" title="" @change="calendarChange"></tui-calendar>
			<sh-bank-picker
			  :data="merchantData"
			  :show="state.showMechant"
			  @cancel="state.showMechant = false"
			  @confirm="bindPickerChange"
			>
			</sh-bank-picker>
		</view>
		
		<stockPicker @confirm="getPicker" ref="stockPickerRef" title="订单分类" :data="state.popData"></stockPicker>
	</s-layout>
</template>

<script setup>
	import sheep from '@/sheep';
	import {
		onShow,
		onLoad
	} from '@dcloudio/uni-app';
	import {
		computed,
		reactive,
		ref,
		nextTick
	} from 'vue';
	import ShBankPicker from '../components/sh-merchant-picker.vue'
	import fuiActionsheet from "../components/fui-actionsheet/fui-actionsheet.vue";
	import uniDatetimePicker from "../components/uni-datetime-picker/uni-datetime-picker.vue"
	import withdrawCard from './component/withdraw-card.vue';
	import tuiCalendar from "./component/tui-calendar/tui-calendar.vue"
	import dayjs from 'dayjs'
	import stockPicker from '../components/stock-picker'
	const state = reactive({
		pageType: 'my',
		tabActive: 1,
		showMoney: false,
		total_income: '0.00',
		pending_amount: '0.00',
		settled_amount: '0.00',
		refunded_amount: '0.00',
		can_withdraw: '0.00',
		timeDate: [],
		source_type: 'platform', // 收益来源类型：platform-平台收益（默认），payment-支付收益
		showType: false,
		//店铺picker显示
		showMechant:false,
		//s店铺列表
		smerchantFilterList:[],
		//h店铺列表
		hmerchantFilterList:[],
		//店铺索引
		shIndex:0,
		stitle:'',
		htitle:'',
		//子店铺标识
		son_code:'',
		
		typeText: '全部收益',
		statusText: '全部结算',
		listType: 'all',
		listStatus: 'all',
		page: 0,
		list: [],
		loadStatus: 'more',

		data: {
			total_money: '0.00', //总收入
			ing_money: '0.00', //待结算
			money: '0.00', //可提现
			refund_money: '0.0', //已退款
		},
		index: 0, // 收益类型 0:商城商户 1:超引擎计划 2:鲸囍供应链
		tab_index: 0, // 收益类型 tab 0:本周 1:本月 2:本年 3:自定义查询
		payList: [],
		startDate: '2000',
		endDate: '',
		year: '',
		num: 0,
		fee: '',
		dateRange: null,
		history_data: {}, // 历史数据
		shop_name: '店铺名称', // 店铺名称
		show: false,
		popData:[]
	});
	const calendar = ref(null);
	const sys_navBar = sheep.$platform.navbar; //标题栏高度
	const {
		screenHeight,
		safeAreaInsets,
		screenWidth,
		safeArea
	} = sheep.$platform.device;
	const statusBarHeight = sheep.$platform.device.statusBarHeight * 2;
	const pageHeight = (safeArea.height + safeAreaInsets.bottom) * 2 + statusBarHeight - sys_navBar - 750;
	const showList = ref([]);
	
	const list = [{
			type: 'my',
			img: '/storage/default/20250423/b3a1385c9d8b5c05c03288883a5671c2.png',
			name: '我的收益',
			link: '/pages/commission/merchant/income',
		},

		{
			type: 'shop',
			img: '/storage/decorate/20250326/5aba0435d9ca780c565c7d6167326a07.png',
			name: '我是商家',
			link: '/pages/merchant/pay_history_list',
		},
	];
	const typeList = [{
			name: "全部收益",
			value: "all"
		},
		{
			name: "商品分享收益",
			value: "payment_pay"
		},
	];
	const statusList = [{
			name: "全部结算",
			value: "all"
		},
		{
			name: "待结算",
			value: "pending"
		},
		{
			name: "已结算",
			value: "settled"
		},
		{
			name: "已退款",
			value: "refunded"
		},
	];
	const btnList = {
		my: [{
				name: '平台收益',
				value: 1
			},
			{
				name: '支付收益',
				value: 3
			},
			{
				name: '我的团队',
				value: 2
			},
		],
		shop:[
			{ name: '商城商户', value: 0 },
			{ name: '超引擎计划', value: 1 },
			{ name:'鲸囍供应链', value:2 },
			{ name:'本地生活商家', value:3 },
		]
	}
	const tabs_list = [{
			name: '本周',
			id: 1
		},
		{
			name: '本月',
			id: 2
		},
		{
			name: '本年',
			id: 3
		},
		{
			name: '自定义查询',
			id: 3
		},
	]
	const tabsList = computed(()=>{
		if(state.index==0||state.index==3){
			return tabs_list;
		} else {
			return tabs_list.slice(0, -1);
		}
	})

	const calcTitle = computed(() => {
		return state.tabActive == 1 ? '我的收益' : (state.tabActive == 2 ? '团队收益' : '支付收益')
	})
	const tabList = computed(() => btnList[state.pageType])
	const pageActive = computed(() => (state.pageType == 'my' ? state.tabActive : state.index));
	//店铺筛选弹窗
	const merchantData = computed(()=>{
		return state.shIndex==1?state.smerchantFilterList:state.hmerchantFilterList;
	})
	
	const dateFilterText = computed(() => {
		if (state.timeDate.length == 0) {
			return '全部时间'
		} else {
			if (state.timeDate[0] === state.timeDate[1]) {
				return state.timeDate[0];
			} else {
				return state.timeDate.join('~');
			}
		}

	});
	onLoad((opt) => {
		if (opt.type) {
			state.type = opt.type
		}
		init()
	});

	const bindDateChange = (e) => {
		console.log(e, '日期change')
		getStoreList(e.detail.value)
	}
	const getDefaultDateRange = () => {
		const today = new Date();
		const yesterday = new Date(today);
		yesterday.setDate(today.getDate() - 1);
		return [yesterday, today];
	};
	// 加载更多
	function loadmore() {
		if (state.loadStatus !== 'noMore') {
			getIncomeList()
		} else {
			uni.showToast({
				title: '没有更多了',
				icon: 'none'
			})
		}
	}
	onShow(() => {});

	function setPage(item) {
		if (state.pageType != item.type) {
			state.pageType = item.type
		} else {
			return
		}
		let tab = {
			...btnList[state.pageType][0]
		}
		state.tabActive = tab.value
		TabChange(tab)
	}

	function onChangeTime(e) {
		state.timeDate[0] = e[0];
		state.timeDate[1] = e[e.length - 1];
		// state.pagination = pagination;
		// getLogList();
		clearList()
		getIncomeList()
	}

	function TabChange(item) {
		if (state.pageType == 'my') {
			incomeChange(item)
		} else {
			changeIndex(item.value)
		}
	}

	function appendTimeHMS(arr) {
		if (arr[0]) {
			return [arr[0] + ' 00:00:00', arr[1] + ' 23:59:59'];
		} else {
			return []
		}
	}

	function typeClick(v) {
		if (state.type == 1) {
			state.typeText = v.text;
			state.listType = typeList[v.index].value
		} else {
			state.statusText = v.text;
			state.listStatus = statusList[v.index].value
		}
		state.showType = false;
		clearList()
		getIncomeList()
	}

	function incomeChange(item) {
		state.tabActive = item.value
		state.settled_amount = '0.00'
		state.refunded_amount = '0.00'
		state.pending_amount = '0.00'
		state.total_income = '0.00'
		state.can_withdraw = '0.00'
		state.source_type = item.value == 1 ? 'platform' : item.value == 3 ? 'payment' : ''
		clearList()
		if (item.value == 1) { // 平台收益
			getIncomeList()
		} else if (item.value == 3) { // 支付收益
			getIncomeList()
		}
	}

	function clearList() {
		state.page = 0
		state.list = []
		state.loadStatus = 'more'
	}

	function init() {
		//获取我的s店铺和h店铺
		getCyqSonStore();

		if (state.pageType == 'my') {
			getIncomeList()
		} else {
			state.dateRange = getDefaultDateRange();
			get_data();
			getJxData();
		}
	}
	async function getJxData(month = []) {
		const {
			error,
			data
		} = await sheep.$api.pay.getJxMoney({
			type: state.tab_index + 1,
			month: month,
		});

		if (error === 0) {
			state.payList = data.list;
			state.num = data.amount.num;
			state.data.total_money = data.amount.total;
			state.data.ing_money = data.amount.paid;
			state.data.money = data.amount.completed;
			state.data.refund = data.amount.refund;
		}
	}
	async function getTgIncome(month = []) {
		const {
			error,
			data
		} = await sheep.$api.merchant.tuangou_income({
			type: state.tab_index + 1,
			month: month,
			income_type:orderType.value.value
		});

		if (error === 0) {
			console.log('data团购收益',data)
			state.payList = data.list;
			state.num = data.amount.num;
			state.data.total_money = data.amount.total;
			state.data.ing_money = data.amount.paid;
			state.data.money = data.amount.completed;
			state.data.refund = data.amount.refund;
		}
	}
	function get_data() {
		sheep.$api.pay.pay_history({
			date: state.dateRange
		}).then(res => {
			state.history_data = res.data
		})
	}

	function openTypeList(e) {
		state.type = e;
		if (e == 1) {
			showList.value = typeList.map(v => v.name)
			state.showType = true;
		} else if (e == 2) {
			showList.value = statusList.map(v => v.name)
			state.showType = true;
		}

		console.log(showList.value,'showList')
	}
	async function getIncomeList() {
		state.loadStatus = 'loading'
		let {
			data,
			error
		} = await sheep.$api.user.income.platformRevenue({
			page: state.page + 1,
			status: state.listStatus,
			type: state.listType,
			date: appendTimeHMS(state.timeDate),
			source_type: state.source_type
		})

		if (error == 0) {
			state.list.push(...data.list.data)
			state.settled_amount = data.settled_amount
			state.refunded_amount = data.refunded_amount
			state.pending_amount = data.pending_amount
			state.total_income = data.total_income
			state.page = data.list.current_page
			state.can_withdraw = data.can_withdraw || '0.00'
			state.loadStatus = data.list.data.length == data.list.per_page ? 'more' : 'no-more'
		}
	}


	const setStartTime = () => {
		state.year = dayjs().format('YYYY')
		state.endDate = dayjs().format('YYYY')
	}
	//获取超引擎计划收益（待结算，可结算，已退款等字段）
	const getStoreData = async () => {
		const {
			error,
			data
		} = await sheep.$api.pay.getStoreMoney()

		if (error === 0) {
			if (data) {
				state.data.total_money = data?.total_money
				state.data.ing_money = data.ing_money
				state.data.money = data.money
			}
		}
	}
	const changeIndex = (e) => {
		state.data = {
			total_money: '0.00', //总收入
			ing_money: '0.00', //待结算
			money: '0.00', //可提现
			refund_money: '0.0', //已退款
		}
		state.index = e
		state.payList = [];
		state.tab_index = 1
		if (state.index === 1) {
			setStartTime()
			setTime()
			getStoreData()
		} else if(state.index === 2){
			getYxData()
			setStartTime()
			setTime()
		}else if(state.index === 0){
			getJxData();
		}else if(state.index === 3){//团购收益
			getTgIncome()
		}
	}


	const jump = () => {
		// if (state.data.money === '0.00') {
		// 	return sheep.$helper.toast('可提现金额为0');
		// }
		sheep.$router.go('/pages/merchant/transfer', {
			type: state.index,
			money:state.data.money
			
		})
	}

	const changeTab = (e) => {
		console.log(e)
		state.tab_index = e;

		state.year = dayjs().format('YYYY')
		if (state.index === 1) {
			setTime()
		} else {
			if (state.index == 2) {
				setTime()
			} else {
				if (state.tab_index == 3) {
					calendar.value && calendar.value.show();
				}
				if(state.index==3){
					getTgIncome()
				}else{
					getJxData();
				}
			}
		
		
		}
	}

	const bindYear = (e) => {
		state.year = e.detail.value
		if (state.index == 1) {
			getStoreList(e.detail.value)
		} else {
			getYxStoreList(e.detail.value)
		}
	}
	// 设置时间
	const setTime = () => {
		let month = ''
		if (state.tab_index === 1) {
			// 默认获取当前月份
			month = dayjs().format('YYYY-MM');
		}
		if (state.tab_index === 2) {
			month = state.year
		}

		if (state.index !== 2) {

			getStoreList(month)
		} else {
			getYxStoreList(month)
		}
	}
	// 我是商家-获取超引擎计划列表
	const getStoreList = async (month) => {
		const {
			error,
			data
		} = await sheep.$api.pay.getStoreList({
			time_type: tabs_list[state.tab_index].id,
			month: month,
			son_code:state.son_code,
		})

		
		if (error === 0) {
			state.son_code = '';
			if (data) {
				if (state.tab_index !== 2) {
					console.log(data, 'list=============')
					state.payList = data
				} else {
					state.num = data.num
					state.fee = data.fee
				}
			} else {
				state.payList = null
			}
		}
	}
	//获取惊喜严选列表
	const getYxStoreList = async (month) => {
		const {
			error,
			data
		} = await sheep.$api.pay.getSurpriseShopOrder({
			time_type: tabs_list[state.tab_index].id,
			month: month
		})
		if (error === 0) {
			if (data) {
				if (state.tab_index !== 2) {
					state.payList = data
				} else {
					state.num = data.num
					state.fee = data.fee
				}
			} else {
				state.payList = null
			}
		}
	}
	async function getYxData(month = []) {
		const {
			error,
			data
		} = await sheep.$api.pay.getSurpriseShop({
			type: state.tab_index + 1,
			month: month,
		});

		if (error === 0 && data) {
			calendar.value.hide
			state.data.total_money = data.total_money;
			state.data.ing_money = data.ing_money;
			state.data.money = data.money;
		}
		setTime()
	}

	function calendarChange(e) {
		let month = '';
		month = [e.startDate, e.endDate]
		getJxData(month);
	}
	//店铺筛选按钮点击事件
	function merchantClick(index){
		state.shIndex = index;
		state.showMechant = true;
	}
	
	function bindPickerChange(e){
		
		state.showMechant = false;
		state.son_code = e.id;
		if(state.shIndex==1){
			state.stitle = e.name;
			state.htitle='';
		}else if(state.shIndex==2){
			state.stitle = '';
			state.htitle = e.name;
		}
		
		getStoreList(dayjs().format('YYYY-MM'));
	}
	
	//获取是否有超引擎店铺
	async function getCyqSonStore() {
		const res = await sheep.$api.store.getCyqSonStore();
		if (res.error == 0) {
			state.smerchantFilterList = res.data.s;
			state.hmerchantFilterList = res.data.h;
		}
	}	
		// 选择团购、外卖订单类型
		const orderType=ref({name:'全部订单',value:'all'})
		const stockPickerRef=ref(null)
		function selecetType(){
			state.popData=[
				{name:'全部订单',value:'all'},
				{name:'外卖订单',value:'takeout'},
				{name:'团购订单',value:'group'},
			]
			stockPickerRef.value.open()
		}
		// 获取picker弹框返回的数据
		function getPicker(e){
			console.log(e)
			orderType.value=e
			getTgIncome()
			
		}
</script>

<style lang="scss" scoped>
@import './style/incomePage.scss';
.scan-btn{
  	
  	padding:10rpx;
  	color:#272636;
  	font-size: 24rpx;
  	border-radius: 24rpx;
  	font-family: PingFang SC;
  	
  		
  	border: 2rpx solid #000000;
  	
  }
  .chao-mer-filter-s {
		width: 50%;
	}

	.chao-mer-filter-s-txt {
		min-width: 160rpx;;
		width: 160rpx;
		height: 49rpx;
		font-family: Source Han Sans;
		font-size: 30rpx;
		font-weight: normal;
		line-height: normal;
		letter-spacing: normal;
		color: #5B5B5B;
	}

	.chao-mer-all {
		text-align: right;
		width:100rpx;
		white-space: nowrap;       
		overflow: hidden;           
		text-overflow: ellipsis;
		height: 43rpx;
		font-family: Source Han Sans;
		font-size: 30rpx;
		font-weight: 550;
		line-height: normal;
		letter-spacing: normal;
		color: #1E1E1E;
	}
</style>